package njust.csc.aeapi.service

import njust.csc.aeapi.config.ApplicationVariables
import njust.csc.aeapi.utils.saveTo
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import org.springframework.web.multipart.MultipartFile
import java.nio.file.Path
import kotlin.io.path.*

/**
 * @Author ZhouHang
 * @Date 24/6/15 周六
 */
@Service
class FileService @Autowired constructor(
    private val applicationVariables: ApplicationVariables
) {
    /**
     * 将文件保存到 user-input-dirname 指定的目录下
     * @param file 需要保存的文件
     * */
    fun saveToUserInput(file: MultipartFile): Path {
        return file.saveTo(Path(applicationVariables.userInputDirPath))
    }
}
